//
// Created by 董一龙 on 2022/10/13.
//

#ifndef FQUEUE_MEMORY_MAP_BUFFER_H
#define FQUEUE_MEMORY_MAP_BUFFER_H

#include <filesystem>
#include <cinttypes>
#include <cstdint>
#include "mmaplib/mmap.h"
#include "mmaplib/platform/platform_interface.h"
#include "mmaplib/platform/mac/macos_adaptation.h"
#include "mmaplib/platform/linux/linux_adaptation.h"
#include "mmaplib/platform/win/windows_adaptation.h"

namespace fqueue {
    using platform = platform_interface<macos_adaptation>;
}
namespace fqueue {
    struct buffer {
        buffer() = default;
        virtual ~buffer() = default;

        [[nodiscard]] virtual uint8_t * data() const = 0;
        [[nodiscard]] virtual size_t size() const = 0;
    };

    struct memory_map_buffer : public buffer {
        memory_map_buffer(std::filesystem::path const& filename, size_t mmap_size);
        ~memory_map_buffer() override = default;

        [[nodiscard]] uint8_t * data() const override;
        [[nodiscard]] size_t size() const override;

    private:
        std::unique_ptr<mmaplib::mmap> m_pMmapObj;
    };
} // fqueue

#endif //FQUEUE_MEMORY_MAP_BUFFER_H
